package test08;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/*
3. 在D盘下，有一c.txt 文件中内容为：HelloWorld
在c.txt文件原内容基础上，添加五句 I love java，而且要实现一句一行操作(注：原文不可覆盖)。
 */
public class TestDemo03 {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\c.txt");
        if (!file.exists()) {
            file.createNewFile();
        }

        /*BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\c.txt",true));
        bw.newLine();
        for (int i = 0; i < 5; i++) {

            bw.write("I love java");
            bw.newLine();
            bw.flush();
        }*/

        FileWriter fileWriter = new FileWriter("D:\\\\c.txt",true);
        fileWriter.write("\r\n");
        for (int i = 0; i < 5; i++) {
            fileWriter.write("I love java");
            fileWriter.write("\r\n");
            fileWriter.flush();
        }
        fileWriter.close();
    }
}
